from jyinterface.interface import *
import time
import datetime

huobi=JyInterface(type_=1, futureOrSpot=1,appKey='afwdf58-429bf211-af0a8',secret='537d119b--ec1af0be-4aa5a',passphrase='',transferId='M_1',grpcAddress="18.183.188.24:9309")
huobi_spot=JyInterface(type_=1, futureOrSpot=0,appKey='afwo04df38-429bf211-af0a8',secret='537d1197c6c-ec1af0be-4aa5a',passphrase='',transferId='M_1',grpcAddress="18.183.188.24:9309")
ok=JyInterface(type_=3, futureOrSpot=1, appKey='e21662ac-1cfe-f-c36684d04c29',secret='3B1B05ADF473E8DB7369E',passphrase='123ab',transferId='M_2',grpcAddress="18.183.188.24:9309")
bian=JyInterface(type_=2, futureOrSpot=1, appKey='PUg0j5h2iliMYIX9vQxEa744fUPBXMAd1zzmlcMeJWP6sYDEf',secret='EL4g3YQ7w4ZQg6hXBIui8dhnINHOyQo7qbjrSiwf3EU5rCrzN3e7k9',passphrase='',transferId='M_3',grpcAddress="18.183.188.24:9309")


def get_data(code_list):
    # code_list=['210326','210402','210625','210924']
    symbol_hb=['BTC','ETH','LINK','DOT','EOS','TRX','LTC','BCH','XRP','BSV','ETC','FIL','ADA']
    symbol_ok=['BTC','ETH','LINK','DOT','EOS','TRX','LTC','BCH','XRP','BSV','ETC','FIL','ADA']
    symbol_bian=['BTC','ETH','LINK','DOT','LTC','BCH','XRP','FIL','ADA']
    huobi_price_future=[]
    ok_price_future=[]
    bian_price_future=[]
    hb_ok_spot=[]
    bian_spot=[]
    for i in symbol_hb:
        for ii in code_list:
            try:
                xx=huobi.getLastPrice(i+ii)
                huobi_price_future.append(xx)
            except:
                huobi_price_future.append(float(1))
    for i in symbol_ok:
        for ii in code_list:
            try:
                yy=ok.getLastPrice(i+ii)
                ok_price_future.append(yy)
            except:
                ok_price_future.append(float(1))
    for i in symbol_bian:
        for ii in code_list:
            try:
                zz=bian.getLastPrice(i+ii)
                bian_price_future.append(zz)
            except:
                bian_price_future.append(float(1))
    for i in symbol_hb:
        try:
            hb_ok_spot.append(huobi_spot.getLastPrice(i+'/USDT'))
        except:
            hb_ok_spot.append(float(1))
    for i in symbol_bian:
        try:
            bian_spot.append(huobi_spot.getLastPrice(i+'/USDT'))
        except:
            bian_spot.append(float(1))
    hb_dif = []
    ok_dif= []
    bian_dif = []
    hb_list = [huobi_price_future[:4],huobi_price_future[4:8],huobi_price_future[8:12],huobi_price_future[12:16],huobi_price_future[16:20],huobi_price_future[20:24],
              huobi_price_future[24:28],huobi_price_future[28:32],huobi_price_future[32:36],huobi_price_future[36:40],huobi_price_future[40:44],huobi_price_future[44:48],huobi_price_future[48:52]]
    ok_list = [ok_price_future[:4],ok_price_future[4:8],ok_price_future[8:12],ok_price_future[12:16],ok_price_future[16:20],ok_price_future[20:24],
              ok_price_future[24:28],ok_price_future[28:32],ok_price_future[32:36],ok_price_future[36:40],ok_price_future[40:44],ok_price_future[44:48],ok_price_future[48:52]]
    bian_list = [bian_price_future[:4],bian_price_future[4:8],bian_price_future[8:12],bian_price_future[12:16],bian_price_future[16:20],bian_price_future[20:24],
              bian_price_future[24:28],bian_price_future[28:32],bian_price_future[32:36]]
    hb_dif = ['%.2f'%((hb_list[i][j]-hb_ok_spot[i])/hb_ok_spot[i]*100) for i in range(len(hb_list))  for j in range(4)]
    ok_dif = ['%.2f'%((ok_list[i][j]-hb_ok_spot[i])/hb_ok_spot[i]*100) for i in range(len(ok_list))  for j in range(4)]
    bian_dif = ['%.2f'%((bian_list[i][j]-bian_spot[i])/bian_spot[i]*100) for i in range(len(bian_list))  for j in range(4)]
    t_today = datetime.datetime.today()
    day1 =  datetime.datetime(int('20'+code_list[0][:2]),int(code_list[0][2:4]),int(code_list[0][4:6]))
    day2 = datetime.datetime(int('20'+code_list[1][:2]),int(code_list[1][2:4]),int(code_list[1][4:6]))
    day3 = datetime.datetime(int('20'+code_list[2][:2]),int(code_list[2][2:4]),int(code_list[2][4:6]))
    day4 = datetime.datetime(int('20'+code_list[3][:2]),int(code_list[3][2:4]),int(code_list[3][4:6]))
    day_list = [(day1-t_today).days+2,(day2-t_today).days+2,(day3-t_today).days+2,(day4-t_today).days+2]
    hb_dif_x = [hb_dif[:4],hb_dif[4:8],hb_dif[8:12],hb_dif[12:16],hb_dif[16:20],hb_dif[20:24],
              hb_dif[24:28],hb_dif[28:32],hb_dif[32:36],hb_dif[36:40],hb_dif[40:44],hb_dif[44:48],hb_dif[48:52]]
    rate = ['%.2f'%(float(hb_dif_x[i][j])/day_list[j]*365) for i in range(len(hb_dif_x))  for j in range(4)]
     
    print('-=======================================================================')
    print('             BTC                    ETH                   LINK                 DOT         ')
    print(f'当周： {hb_dif[0]}  {ok_dif[0]}  {bian_dif[0]}   /   {hb_dif[4]}  {ok_dif[4]}  {bian_dif[4]}   /   {hb_dif[8]}  {ok_dif[8]}  {bian_dif[8]}   /   {hb_dif[12]}  {ok_dif[12]}  {bian_dif[12]}')
    print(f'次周： {hb_dif[1]}  {ok_dif[1]}  {bian_dif[1]}   /   {hb_dif[5]}  {ok_dif[5]}  {bian_dif[5]}   /   {hb_dif[9]}  {ok_dif[9]}  {bian_dif[9]}   /   {hb_dif[13]}  {ok_dif[13]}  {bian_dif[13]}')
    print(f'当季： {hb_dif[2]}  {ok_dif[2]}  {bian_dif[2]}   /   {hb_dif[6]}  {ok_dif[6]}  {bian_dif[6]}   /   {hb_dif[10]}  {ok_dif[10]}  {bian_dif[10]}   /   {hb_dif[14]}  {ok_dif[14]}  {bian_dif[14]}')
    print(f'次季： {hb_dif[3]}  {ok_dif[3]}  {bian_dif[3]} / {hb_dif[7]}  {ok_dif[7]}  {bian_dif[7]}  /  {hb_dif[11]}  {ok_dif[11]}  {bian_dif[11]}  /  {hb_dif[15]}  {ok_dif[15]}  {bian_dif[15]}')
    print(f'{rate[0]} {rate[1]} {rate[2]} {rate[3]} -- {rate[4]} {rate[5]} {rate[6]} {rate[7]} -- {rate[8]} {rate[9]} {rate[10]} {rate[11]} -- {rate[12]} {rate[13]} {rate[14]} {rate[15]}')
    
    print('             EOS                    TRX                   LTC                 BCH         ')
    print(f'当周： {hb_dif[16]}  {ok_dif[16]}  **   /   {hb_dif[20]}  {ok_dif[20]}  **   /   {hb_dif[24]}  {ok_dif[24]}  {bian_dif[16]}   /   {hb_dif[28]}  {ok_dif[28]}  {bian_dif[20]}')
    print(f'次周： {hb_dif[17]}  {ok_dif[17]}  **   /   {hb_dif[21]}  {ok_dif[21]}  **  /   {hb_dif[25]}  {ok_dif[25]}  {bian_dif[17]}    /   {hb_dif[29]}  {ok_dif[29]}  {bian_dif[21]}')
    print(f'当季： {hb_dif[18]}  {ok_dif[18]}  **   /   {hb_dif[22]}  {ok_dif[22]}  **   /   {hb_dif[26]}  {ok_dif[26]}  {bian_dif[18]}    /   {hb_dif[30]}  {ok_dif[30]}  {bian_dif[22]}')
    print(f'次季： {hb_dif[19]}  {ok_dif[19]}  ** /   {hb_dif[23]}  {ok_dif[23]}  **   /   {hb_dif[27]}  {ok_dif[27]}  {bian_dif[19]}   /  {hb_dif[31]}  {ok_dif[31]}  {bian_dif[23]}')
    print(f'{rate[16]} {rate[17]} {rate[18]} {rate[19]} -- {rate[20]} {rate[21]} {rate[22]} {rate[23]} -- {rate[24]} {rate[25]} {rate[26]} {rate[27]} -- {rate[28]} {rate[29]} {rate[30]} {rate[31]}')
    
    print('             XRP                    BSV                   ETC                 FIL         ')
    print(f'当周： {hb_dif[32]}  {ok_dif[32]}  {bian_dif[24]}   /   {hb_dif[36]}  {ok_dif[36]}  **   /   {hb_dif[40]}  {ok_dif[40]}  **   /   {hb_dif[44]}  {ok_dif[44]}  {bian_dif[28]}')
    print(f'次周： {hb_dif[33]}  {ok_dif[33]}  {bian_dif[25]}   /   {hb_dif[37]}  {ok_dif[37]}  **   /   {hb_dif[41]}  {ok_dif[41]}  **   /   {hb_dif[45]}  {ok_dif[45]}  {bian_dif[29]}')
    print(f'当季： {hb_dif[34]}  {ok_dif[34]}  {bian_dif[26]}   /   {hb_dif[38]}  {ok_dif[38]}  **   /   {hb_dif[42]}  {ok_dif[42]}  **   /   {hb_dif[46]}  {ok_dif[46]}  {bian_dif[30]}')
    print(f'次季： {hb_dif[35]}  {ok_dif[35]}  {bian_dif[27]}  /  {hb_dif[39]}  {ok_dif[39]}  **   /   {hb_dif[43]}  {ok_dif[43]}  **   /  {hb_dif[47]}  {ok_dif[47]}  {bian_dif[31]}')
    print(f'{rate[32]} {rate[33]} {rate[34]} {rate[35]} -- {rate[36]} {rate[37]} {rate[38]} {rate[39]} -- {rate[40]} {rate[41]} {rate[42]} {rate[43]} -- {rate[44]} {rate[45]} {rate[46]} {rate[47]}')
    
    
while True:
    get_data(['210430','210507','210625','210924'])
    time.sleep(300)
    
    





